#!/usr/bin/env python
# coding:utf-8
# Author:  mozman
# Purpose: svg examples
# Created: 08.09.2010
# Copyright (C) 2010, Manfred Moitzi
# License: MIT License
try:
    import svgwrite
    from svgwrite.masking import Mask
except ImportError:
    # if svgwrite is not 'installed' append parent dir of __file__ to sys.path
    import sys
    from pathlib import Path

    sys.path.insert(0, str(Path(__file__).resolve().parent.parent))

import svgwrite


def simple_text(name):
    dwg = svgwrite.Drawing(name, (500, 400), debug=True, style="background:green")
    # dwg.add(dwg.rect(insert=(150, 100), size=(100, 200), fill="white"))
    paragraph = dwg.add(
        dwg.g(
            font_size=14,
            dominant_baseline="middle",
            text_anchor="middle",
        )
    )
    paragraph.add(dwg.rect(insert=(150, 100), size=(100, 200), fill="white"))
    # different formats can be used by the TSpan element
    # The atext.tspan(...) method is a shortcut for: atext.add(dwg.tspan(...))
    atext = dwg.text("", insert=(30, 30), textLength=80)
    atext.add(dwg.tspan("发电", fill="red"))
    # text color is set by the 'fill' property and 'stroke sets the outline color.
    atext.add(dwg.tspan("供热", fill="red", dy=[15], x=[30]))
    # atext.add(dwg.tspan(" is a Word!", dy=["1em"], font_size="0.7em", fill="green"))

    paragraph.add(atext)

    dwg.save(pretty=True)


if __name__ == "__main__":
    simple_text("simple_text3.svg")
